﻿/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace PickGold.Util.WordSpliter
{
	class Delimiter : Dictionary<string, string>
	{
		public Delimiter(string[] delimiters)
		{
			foreach (var item in delimiters)//按行读取中文停用词
			{
				if (string.IsNullOrEmpty(item))
					continue;

				var key = item;
				if (key[0] < 128)
					key = key.ToLower();
				if (!this.ContainsKey(key))//如果哈希表中不包括该停用词则添加到哈希表中
					this.Add(key, item);
			}
		}

		public bool IsDelimiter(string word, bool filterEnglish, int filterEnglishLength, bool filterNumeric, int filterNumericLength)
		{
			if (string.IsNullOrEmpty(word))
				return false;

			var key = word;

			if (word[0] < 128)
			{
				if (filterEnglish && word.Length > filterEnglishLength && (word[0] < '0' || word[0] > '9'))
					return true;

				if (filterNumeric && word.Length > filterNumericLength && (word[0] >= '0' && word[0] <= '9'))
					return true;

				key = word.ToLower();
			}
			return this.ContainsKey(key);
		}
	}
}
